# -*- coding: utf-8 -*-

import json
from mitmproxy import http
from spider import Spider
# 实例化爬虫
spider = Spider()

def request(flow: http.HTTPFlow) -> None:
    # 将请求新增了一个查询参数
    flow.request.query["mitmproxy"] = "rocks"

def response(flow: http.HTTPFlow) -> None:
    # 将响应头中新增了一个自定义头字段
    flow.response.headers["newheader"] = "foo"

    if 'www.iesdouyin.com/web/api/v2/aweme/post/?' in flow.request.url:

        res = json.loads( flow.response.text )

        for item in (res["aweme_list"]):
            data = {
                "aweme_id": item["aweme_id"],
                "desc": item["desc"]
            }

            spider.RequestIndex( data )


